﻿<#escape x as x?html>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>主界面</title>
    <link rel="stylesheet" type="text/css" href="${rc.contextPath}/Resources/style/style.css">
    <script type="text/javascript" src="${rc.contextPath}/Resources/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="${rc.contextPath}/Resources/js/share.js"></script>
    <script type="text/javascript" src="${rc.contextPath}/Resources/js/json2.js"></script>
    <script type="text/javascript" src="${rc.contextPath}/Resources/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${rc.contextPath}/Resources/js/jquery.linkbutton.js"></script>
    <script type="text/javascript" src="${rc.contextPath}/Resources/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${rc.contextPath}/Resources/js/jquery.datebox.js"></script>
    <script type="text/javascript" src="${rc.contextPath}/Resources/js/jquery.url.js"></script>
    <link rel="stylesheet" type="text/css" href="${rc.contextPath}/Resources/style/easyui.css">
    <link rel="stylesheet" type="text/css" href="${rc.contextPath}/Resources/style/icon.css">
    <style type="text/css">
		body,td,th {
			font-family: "Microsoft YaHei";
		}
		a:visited {
			color: #44655C;
		}
		a:active {
			color: #2A3643;
		}
		a:hover {
			color: #293542;
		}
	</style>
	<script type="text/javascript">
		/////////////////////////////////////
        var username = "${Session["currentUser"].username}";
        var fullName = "${Session["currentUser"].fullName}";
        var role = "${Session["currentUser"].role}";
		function hideLi() {
			if (role == 1) {
				$("#h_zb_text").show();
				$("#zb_text").show();
				$("#h_zb_qx").hide();
				$("#zb_qx").hide();
			} else if (role == 2) {
				$("#h_zb_text").show();
				$("#zb_text").show();
				$("#h_zb_qx").show();
				$("#zb_qx").show();
			} else {
				$("#h_zb_text").hide();
				$("#zb_text").hide();
				$("#h_zb_qx").hide();
				$("#zb_qx").hide();
			}
		}
		function changeQx(i) {
			var flag = $('#qx' + i).text();
			if (flag == '授予权限') {
				$.ajax({
			        type: 'POST',
			        url:  "user/setUserRole?userIds=" + i + "&roleType=1",
			        dataType: "json",
			        success: function (data) {
			        	alert("授权成功！");
			        	$('#qx' + i).text("取消权限");
			        }
		    	});
			} else {
				$.ajax({
			        type: 'POST',
			        url:  "user/setUserRole?userIds=" + i + "&roleType=0",
			        dataType: "json",
			        success: function (data) {
			        	alert("取消成功！");
			        	$('#qx' + i).text("授权权限");
			        }
			    });
			}
		}
		
		function deleteRecord(id) {
			$.ajax({
		        type: 'POST',
		        url:  "dutyrecord/remove/" + id + "",
		        dataType: "json",
		        success: function (data) {
		        	if (data.result == 1) {
		        		alert("删除成功！");
		        		loadList();
		        	} else {
		        		alert("删除失败！");
		        	}
		        }
		    });
		}
		
		function prevSQPage() {
			goToSQPage($('#currentPage').val() - 1);
		}
		
		function nextSQPage() {
			goToSQPage(parseInt($('#currentPage').val()) + 1);
		}
		 function goToSQPage(page) {
            var $records = $('#records');
            var $pager = $('#pager');
            var $currentPage = $('#currentPage');
            var $totalPages = $('#totalPages');
            var $totalCount = $('#totalCount');
    		$currentPage.val(page);
            var roleType = "";
            if ($('#RadioGroup1_0').is(":checked")) {
            	roleType = "1";
            } else {
            	roleType = "0";
            }
        	 $.ajax({
		        type: 'POST',
		        url:  "user/query?roleType=" + roleType + "&rows=15&page=" + $currentPage.val(),
		        dataType: "json",
		        success: function (data) {
		        	var content = "<tr><th width='25%' scope='col'>序号</th><th width='25%' scope='col'>用户名</th><th width='25%' scope='col'>用户名称</th><th width='25%' scope='col'>权限</th></tr>";
		            for (var i in data.rows) {
                        var entityJson = JSON.stringify(data.rows[i]);
		            	content += "<tr><td>" + data.rows[i].id + "</td><td>" + data.rows[i].username + "</td><td>" + data.rows[i].fullName + "</td>";
		            	if (data.rows[i].role != 0) {
		            		content += "<td><a id='qx" + data.rows[i].id + "' onclick='changeQx(" + data.rows[i].id + ");'>取消权限</a></td></tr>";
		            	} else {
		            		content += "<td><a id='qx" + data.rows[i].id + "'  onclick='changeQx(" + data.rows[i].id + ");'>授予权限</a></td></tr>";
		            	}
		            }
		            $records.html(content);
		            var count = data.total;
		            var pageSize = 16;
		            var pageNum = parseInt(count / pageSize);
		            if (count % pageSize != 0) {
		            	pageNum++;
		            }
		            $totalPages.val(pageNum);
		            $totalCount.val(count);
		            var pageContent = "上一页<";
		            if ($currentPage.val() > 1) {
		            	pageContent = "<a onclick='prevSQPage();'>上一页</a><";
		     		}
		            if (pageNum > 10) {
		            	
		            } else {
		            	for (var i = 1; i <= pageNum; i++) {
		            		if ($currentPage.val() != i ) {
		            			pageContent += "&nbsp;<a onclick='goToSQPage(" + i + ")'>" + i + "</a>&nbsp;";
		            		} else {
		            			pageContent += "&nbsp;" + i + "&nbsp;";
	            			}
		            	}
		            }
		            if ($currentPage.val() < $totalPages.val()) {
		            	pageContent += "><a onclick='nextSQPage();'>下一页</a>";
		            } else {
		            	pageContent += ">下一页";
		            }
		            $pager.html(pageContent);
		        }
	        });
        }
		/////////////////////////////////////
		function prevQXPage() {
			goToQXPage($('#currentPage').val() - 1);
		}
		function nextQXPage() {
			goToQXPage(parseInt($('#currentPage').val()) + 1);
		}
		 function goToQXPage(page) {
            var $records = $('#records');
            var $pager = $('#pager');
            var $currentPage = $('#currentPage');
            var $totalPages = $('#totalPages');
            var $totalCount = $('#totalCount');
    		 $currentPage.val(page);
    		 var m = $('#dutyTime').val();
    		 //var dt = $('#entryTime').val();
        	 $.ajax({
		        type: 'POST',
		        url:  "dutyrecord/query",
		        data: {
		        	dutyMan:$('#dutyMan').val(),
		        	dutyTime:$('#dutyTime').val(),
		        	//entryTime:$('#entryTime').val(),
		        	rows:16,
		        	page:$currentPage.val()
		        },
		        dataType: "json",
		        success: function (data) {
		        	var content = "";
		            for (var i in data.rows) {
                        	var entityJson = JSON.stringify(data.rows[i]);
		            	if (username == data.rows[i].dutyMan) {
	                        if($.browser.msie) {
	                        	content += "<li><a onclick='ieShowTip(" + entityJson + ")'>值班记录&nbsp;&nbsp;&nbsp;&nbsp;日期：&nbsp;" + data.rows[i].dutyTime + "</a><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onclick='loadUpdateText(" + data.rows[i].id + ");'>修改</a>&nbsp;&nbsp;<a onclick='deleteRecord(" + data.rows[i].id + ");'>删除</a></span><span>值班人：&nbsp;" + data.rows[i].dutyManFullName + "</span></li>";
			            	} else {
			            		content += "<li style='background-color:#FFC1C1'><a onclick='showTip(event, " + entityJson + ")'>值班记录&nbsp;&nbsp;&nbsp;&nbsp;日期：&nbsp;" + data.rows[i].dutyTime + "</a><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onclick='loadUpdateText(" + data.rows[i].id + ");'>修改</a>&nbsp;&nbsp;<a onclick='deleteRecord(" + data.rows[i].id + ");'>删除</a></span><span>值班人：&nbsp;" + data.rows[i].dutyManFullName + "</span></li>";
			            	}
		            	} else {
	                        if($.browser.msie) {
	                        	content += "<li><a onclick='ieShowTip(" + entityJson + ")'>值班记录&nbsp;&nbsp;&nbsp;&nbsp;日期：&nbsp;" + data.rows[i].dutyTime + "</a><span>值班人：&nbsp;" + data.rows[i].dutyManFullName + "</span></li>";
			            	} else {
			            		content += "<li><a onclick='showTip(event, " + entityJson + ")'>值班记录&nbsp;&nbsp;&nbsp;&nbsp;日期：&nbsp;" + data.rows[i].dutyTime + "</a><span>值班人：&nbsp;" + data.rows[i].dutyManFullName + "</span></li>";
			            	}
		            	}
		            }
		            $records.html(content);
		            var count = data.total;
		            var pageSize = 16;
		            var pageNum = parseInt(count / pageSize);
		            if (count % pageSize != 0) {
		            	pageNum++;
		            }
		            $totalPages.val(pageNum);
		            $totalCount.val(count);
		            var pageContent = "上一页<";
		            if ($currentPage.val() > 1) {
		            	pageContent = "<a onclick='prevQXPage();'>上一页</a><";
		     		}
		            if (pageNum > 10) {
		            	
		            } else {
		            	for (var i = 1; i <= pageNum; i++) {
		            		if ($currentPage.val() != i ) {
		            			pageContent += "&nbsp;<a onclick='goToQXPage(" + i + ")'>" + i + "</a>&nbsp;";
		            		} else {
		            			pageContent += "&nbsp;" + i + "&nbsp;";
	            			}
		            	}
		            }
		            if ($currentPage.val() < $totalPages.val()) {
		            	pageContent += "><a onclick='nextQXPage();'>下一页</a>";
		            } else {
		            	pageContent += ">下一页";
		            }
		            $pager.html(pageContent);
		        }
	        });
        }
		$(function() {
			var now=new Date();
			var $d = $('#now');
			$d.html("<span style='padding-left:46px;'>今天是"+now.getFullYear() + "年" + (now.getMonth()+1) + "月"+ now.getDate() + "日</span>");
			//////////////////////////////////////////////////////
			loadList();
			//////////////////////////////////////////////////////
		});
		function loadList() {
			var $content = $('#contont');
			$content.load('list', function() {
				$("ul.accordion a.item").click(function ()
	            {
	                
	                    $("ul.inner").slideUp("fast");
	                    $(this).parent("li").find("ul.inner").slideDown("fast");
	            })
	
	            $("div.panel a.expand").click(function ()
	            {
	                if ($(this).hasClass("off")) {
	                    $(this).removeClass("off");
	                    $(this).parents(".panel").find(".content").slideDown("fast");
	                }
	                else {
	                    $(this).addClass("off");
	                    $(this).parents(".panel").find(".content").slideUp("fast");
	                }
	            })
            	goToQXPage(1);
			    $("#dutyTime").datebox({
			    	onSelect: function(date){   
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
            			$("#dutyTime").val(v);   
        			},  
			    	formatter: function(date) {
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
			    		return v;
			    	},
			    	editable: false
			    });
			    $("#entryTime").datebox({
			    	onSelect: function(date){   
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
            			$("#entryTime").val(v);   
        			},  
			    	formatter: function(date) {
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
			    		return v;
			    	},
			    	editable: false
			    });
				hideLi();
			});
		}
		function loadText() {
			var $content = $('#contont');
			$content.load('text', function() {
				 $("ul.accordion a.item").click(function ()
		            {
		                    $("ul.inner").slideUp("fast");
		                    $(this).parent("li").find("ul.inner").slideDown("fast");
		            })
	
	            $("div.panel a.expand").click(function ()
	            {
	                if ($(this).hasClass("off")) {
	                    $(this).removeClass("off");
	                    $(this).parents(".panel").find(".content").slideDown("fast");
	                }
	                else {
	                    $(this).addClass("off");
	                    $(this).parents(".panel").find(".content").slideUp("fast");
	                }
	            })
				hideLi();$("#dutyTime").datebox({
			    	onSelect: function(date){   
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
            			$("#dutyTime").val(v);   
        			},  
			    	formatter: function(date) {
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
			    		return v;
			    	},
			    	editable: false
			    });
			    $("#entryTime").datebox({
			    	onSelect: function(date){   
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
            			$("#entryTime").val(v);   
        			},  
			    	formatter: function(date) {
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
			    		return v;
			    	},
			    	editable: false
			    });
			});
		}
		function loadUpdateText(id) {
			$('#updateId').val(id);
			var $content = $('#contont');
			$content.load('updatetext?id=' + id, function() {
				 $("ul.accordion a.item").click(function ()
		            {
		                    $("ul.inner").slideUp("fast");
		                    $(this).parent("li").find("ul.inner").slideDown("fast");
		            })
	
	            $("div.panel a.expand").click(function ()
	            {
	                if ($(this).hasClass("off")) {
	                    $(this).removeClass("off");
	                    $(this).parents(".panel").find(".content").slideDown("fast");
	                }
	                else {
	                    $(this).addClass("off");
	                    $(this).parents(".panel").find(".content").slideUp("fast");
	                }
	            })
				hideLi();
				$.ajax({
			        type: 'POST',
			        url:  "dutyrecord/queryone/" + $('#updateId').val(),
			        dataType: "json",
			        success: function (data) {
			        	if (data != null) {
			        		$('#id').val(data.id);
			        		$('#dutyMan').val(data.dutyMan);
			        		$('#dutyManFullName').val(data.dutyManFullName);
			        		$('#dutyTime').datebox("setValue", data.dutyTime);
							if (data.entryTime != null) {
				        		$('#entryTime').datebox("setValue", data.entryTime); 
							} else {
				        		$('#entryTime').datebox("setValue", data.entryTime); 
							}
			        		$('#productionSituation').val(data.productionSituation);
			        		$('#security').val(data.security);
			        		$('#securityProduction').val(data.securityProduction);
			        		$('#postResponsibility').val(data.postResponsibility);
			        		$('#leftProlem').val(data.leftProlem);
			        	}
			        }
			    });
			   $("#dutyTime").datebox({
			    	onSelect: function(date){   
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
            			$("#dutyTime").val(v);   
        			},  
			    	formatter: function(date) {
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
			    		return v;
			    	},
			    	editable: false
			    });
			    $("#entryTime").datebox({
			    	onSelect: function(date){   
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
            			$("#entryTime").val(v);   
        			},  
			    	formatter: function(date) {
			    		var m = date.getMonth() + 1;
			    		if (m < 10) {
			    			m = "0" + m;
			    		}
			    		var d = date.getDate();
			    		if (d < 10) {
			    			d = "0" + d;
			    		}
			    		var v = date.getFullYear() + "-" + m + "-" + d;
			    		return v;
			    	},
			    	editable: false
			    });
		    });
		}
		function loadAuthority() {
			var $content = $('#contont');
			$content.load('authority', function() {
            	goToSQPage(1);
				hideLi();
			});
		}
	</script>
</head>
<body>
    <div class="header">
        <img class="logo" src="${rc.contextPath}/Resources/images/bgs/logincio.png">
        <div class="divide"></div>
        <div class="func">
            <a class="button round dark" href="#">首&nbsp;页</a>
            <a class="button round blood" onclick="loginout();">退&nbsp;出</a>
        </div>
    </div>
   
    <div class="tool">
        <div id="now" class="info"></div>
        <ul class="trace" style="margin-top: 0px;">
            <li><a href="#"><img class="png" src="${rc.contextPath}/Resources/images/icon/icon_home.png" /></a></li>
            <li><a onclick="loadList();">值班信息检索</a></li>
            <li id="h_zb_text"><a onclick="loadText();">值班信息录入</a></li>
            <li id="h_zb_qx"><a onclick="loadAuthority();">权限分配</a></li>
        </ul>
    </div>
    <div id="contont"></div>
    <input id='updateId' type='hidden'>
    <div class="footer">独山子石化原油处</div>
</body>

</html>
</#escape>